package cn.edu.jsu.official.pojo.vo;

import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;

import java.util.List;

/**
 * @author Mo
 * @createTime 2022/5/24 21:39
 * @description 分页
 */
public class PageModel<T> {
    @ApiModelProperty("结果集")
    private List<T> data;
    @ApiModelProperty("查询记录数")
    private Integer rowCount;
    @ApiModelProperty("每页多少数据")
    private Integer pageSize = 20;
    @ApiModelProperty("第几页")
    private Integer pageNumber = 1;
    @ApiModelProperty("跳过页数")
    private Integer skip = 0;

    /**
     * 返回总页数
     * @return
     */
    public Integer getTotalPages() {
        return (rowCount + pageSize - 1) / pageSize;
    }

    public PageModel() {
    }

    public PageModel(List<T> data, Integer rowCount, Integer pageSize, Integer pageNumber, Integer skip) {
        this.data = data;
        this.rowCount = rowCount;
        this.pageSize = pageSize;
        this.pageNumber = pageNumber;
        this.skip = skip;
    }

    @Override
    public String toString() {
        return "PageModel{" +
                "data=" + data +
                ", rowCount=" + rowCount +
                ", pageSize=" + pageSize +
                ", pageNumber=" + pageNumber +
                ", skip=" + skip +
                '}';
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public Integer getRowCount() {
        return rowCount;
    }

    public void setRowCount(Integer rowCount) {
        this.rowCount = rowCount;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(Integer pageNumber) {
        this.pageNumber = pageNumber;
    }

    public Integer getSkip() {
        skip = (pageNumber - 1) * pageSize;
        return skip;
    }

    public void setSkip(Integer skip) {
        this.skip = skip;
    }
}
